<template>
	<view class="container">
		<view class="item" v-for="item in list" :key="item.id">
			<view class="" style="padding: 0 30rpx;">
				<view class="row">
					<text>姓名</text>
					<text>{{ item.truename }}</text>
				</view>
				<view class="row">
					<text>性别</text>
					<text>{{ item.gender }}</text>
				</view>
				<view class="row">
					<text>出生年月</text>
					<text>{{ item.birthday }}</text>
				</view>
				<view class="row">
					<text>身高</text>
					<text>{{ item.height }}cm</text>
				</view>
				<view class="row">
					<text>体重</text>
					<text>{{ item.weight }}kg</text>
				</view>
				<view class="row">
					<text>联系方式</text>
					<text>{{ item.mobile }}</text>
				</view>
				<view class="row">
					<text>文化程度</text>
					<text>{{ item.education }}</text>
				</view>
				<view class="row">
					<text>职业</text>
					<text>{{ item.occupation }}</text>
				</view>
				<view class="row">
					<text>血型</text>
					<text>{{ item.blood_group }}</text>
				</view>
				<view class="row">
					<text>近年是否有手术情况</text>
					<text>{{ item.is_shoushu == 1 ? '是' : '否' }}</text>
				</view>
				<view class="row" v-if="item.is_shoushu == 1">
					<text>手术年限</text>
					<text>{{ item.ssnx }}</text>
				</view>
			</view>
			<view class="foot">
				<text @click="edit(item.id)">编辑</text>
				<text @click="del(item.id)">删除</text>
			</view>
		</view>
		<view class="footer">
			<u-button @click="$util.to('/pages/user/archives')" type="success">新增档案</u-button>
		</view>
		<u-empty v-if="list.length == 0 && status != 'loading'" text="还没有相关数据哟!" mode="order" margin-top="300"></u-empty>
		<u-loadmore v-else :status="status" margin-bottom="30" margin-top="30" />
	</view>
</template>

<script>
	import { ehrList, delEhr } from '@/api/api'
	export default {
		data() {
			return {
				list: [],
				status: 'loading',
			};
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				ehrList().then(res => {
					this.list = res.data
					this.status = 'nomore'
				})
			},
			edit(id) {
				this.$util.to('/pages/user/archives?id=' + id)
			},
			del(id) {
				let that = this;
				uni.showModal({
					title: '温馨提示',
					content: '是否确认删除该档案？',
					success: function (res) {
						if (res.confirm) {
							delEhr({id}).then(res => {
								console.log(res)
								if(res.code == 1) {
									uni.showToast({
										title: res.msg,
										success: () => {
											setTimeout(() => {
												that.getList()
											}, 1000)
										}
									})
								} else {
									that.$u.toast(res.msg)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.container {
	width: 100%;
	padding: 20rpx;
	padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
	.item {
		width: 100%;
		background-color: #fff;
		padding: 30rpx 0 0;
		border-radius: 10rpx;
		font-size: 32rpx;
		margin-bottom: 20rpx;
		.row {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;
		}
		.foot {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			border-top: 1px solid #eee;
			margin-top: 30rpx;
			text {
				display: block;
				flex: 1;
				text-align: center;
				padding: 30rpx;
				color: #f44336;
				&:first-child {
					border-right: 1px solid #eee;
					color: #03a9f4;
				}
			}
		}
	}
}
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	height: calc(120rpx + env(safe-area-inset-bottom));
	background-color: #fff;
	z-index: 99;
	padding: 20rpx 30rpx 0;
	padding-bottom: env(safe-area-inset-bottom);
}
</style>
